package com.canaan.business.controller.pc.basic;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.basic.StockStrategy;
import com.canaan.business.service.basic.IStockStrategyService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 库存策略Controller
 *
 * @author canaan
 * @date 2025-04-15
 */
@Api(tags = "库存策略")
@RestController
@RequestMapping("/basic/stockStrategy")
public class StockStrategyController extends BaseController {
    @Resource
    private IStockStrategyService stockStrategyService;

    /**
     * 查询库存策略列表
     */
    @ApiOperation(value = "查询库存策略列表")
    @PreAuthorize("@ss.hasPermi('basic:stockStrategy:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockStrategy stockStrategy) {
        startPage();
        List<StockStrategy> list = stockStrategyService.selectStockStrategyList(stockStrategy);
        return getDataTable(list);
    }

    /**
     * 导出库存策略列表
     */
    @ApiOperation(value = "导出库存策略列表")
    @PreAuthorize("@ss.hasPermi('basic:stockStrategy:export')")
    @Log(title = "库存策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockStrategy stockStrategy) {
        List<StockStrategy> list = stockStrategyService.selectStockStrategyList(stockStrategy);
        ExcelUtil<StockStrategy> util = new ExcelUtil<StockStrategy>(StockStrategy.class);
        util.exportExcel(response, list, "库存策略数据");
    }

    /**
     * 获取库存策略详细信息
     */
    @ApiOperation(value = "获取库存策略详细信息")
    @PreAuthorize("@ss.hasPermi('basic:stockStrategy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockStrategyService.selectStockStrategyById(id));
    }

    /**
     * 新增库存策略
     */
    @ApiOperation(value = "新增库存策略")
    @PreAuthorize("@ss.hasPermi('basic:stockStrategy:add')")
    @Log(title = "库存策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockStrategy stockStrategy) {
        return toAjax(stockStrategyService.insertStockStrategy(stockStrategy));
    }

    /**
     * 修改库存策略
     */
    @ApiOperation(value = "修改库存策略")
    @PreAuthorize("@ss.hasPermi('basic:stockStrategy:edit')")
    @Log(title = "库存策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockStrategy stockStrategy) {
        return toAjax(stockStrategyService.updateStockStrategy(stockStrategy));
    }

    /**
     * 删除库存策略
     */
    @ApiOperation(value = "删除库存策略")
    @PreAuthorize("@ss.hasPermi('basic:stockStrategy:remove')")
    @Log(title = "库存策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockStrategyService.deleteStockStrategyByIds(ids));
    }
}
